MyAddon = LibStub("AceAddon-3.0"):NewAddon("Ndui-Extend", "AceConsole-3.0", "AceEvent-3.0")


-- db
local defaults = {
    profile = {
        showInHead = 2,
        combatOn = true,
        fuEqStats = true,
        combatY = -160,
        -- combatX = 0,
    }

}


-- 首次加载插件时
function MyAddon:OnInitialize()
    -- 注册数据库
    _G["AddonUiDB"] = LibStub("AceDB-3.0"):New("NduiExtendDB", defaults, true)
    local options= {
        name="Ndui-Extend",
        handler=MyAddon,
        type="group",
        args= {

            authorText = {
                type = "description",
                name = "NDui 扩展插件",
                fontSize = "medium",
                order = 2,
            },
            generalHeader = {
                type = "header",
                name = '头像增强',
                order = 100,
            },
            -- showInChat= {
            --     type="toggle",
            --     name="头像隐藏",
            --     desc="隐藏Ndui头像",
            --     order = 101,
            --     get="IsShowInChat",
            --     set="ToggleShowInChat",
            -- },
            headFormat = {
                type = "select",
                name = '头像增强',
                desc = '头像增强',
                values = {
                    [1] = '默认隐藏',
                    [2] = '禁止隐藏',
                    [3] = '完全隐藏',
                },
                sorting = {
                    [1] = 1,
                    [2] = 2,
                    [3] = 3,
                },
                order = 102,
                get = "IsheadShow",
                set = "IsheadSet",
            },
            combatHeader = {
                type = "header",
                name = '战斗增强',
                order = 110,
            },
            combatOn= {
                type="toggle",
                name="开启",
                desc="战斗提示增强",
                order = 111,
                get="IscombatOn",
                set="IscombatOff"
            },
            _combatY= {
                type="input",
                name='Y坐标',
                desc='距离顶部距离',
                get="GetCombatY",
                set="SetCombatY",
                order = 112,
            },
            -- _combatX= {
            --     type="input",
            --     name='X坐标',
            --     desc='距离顶部距离',
            --     get="GetCombatX",
            --     set="SetCombatX",
            --     order = 113,
            -- },
            fuEqStatsHeader = {
                type = "header",
                name = '属性换算',
                order = 120,
            },
            fuEqStatsT= {
                type="toggle",
                name="开启",
                desc="装备属性换算",
                order = 121,
                get="fuEqStatsOn",
                set="fuEqStatsOff"
            },
        }
        ,
    }
    


    self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon", "Ndui-Extend")
    -- 为了实现这一点，我们首先需要稍微处理一下我们的聊天指令
    LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon", options)
    self:RegisterChatCommand("nde", "cmd")

    -- MyAddon.combatOn = true
end

-- 启用插件时
function MyAddon:OnEnable()
    -- Called when the addon is enabled
    -- self:Print("Hello World! OnEnable")

end

-- 输出斜杠命令 触发
function MyAddon:cmd(input)
    if not input or input:trim() == "" then
        InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
    else
        LibStub("AceConfigCmd-3.0"):HandleCommand("nde", "MyAddon", input)
    end
end

function MyAddon:IsheadShow(info)
    return _G["AddonUiDB"].profile.showInHead
end

function MyAddon:IsheadSet(info, value)
    _G["AddonUiDB"].profile.showInHead = value
end

function MyAddon:IscombatOn(info)
    return _G["AddonUiDB"].profile.combatOn
end

function MyAddon:IscombatOff(info, value)
    _G["AddonUiDB"].profile.combatOn = value
end

function MyAddon:GetCombatY(info)
    return _G["AddonUiDB"].profile.combatY
end

function MyAddon:SetCombatY(info, value)
    _G["AddonUiDB"].profile.combatY = value
end

-- function MyAddon:GetCombatX(info)
--     return _G["AddonUiDB"].profile.combatX
-- end

-- function MyAddon:SetCombatX(info, value)
--     _G["AddonUiDB"].profile.combatX = value
-- end

function MyAddon:fuEqStatsOn(info)
    return _G["AddonUiDB"].profile.fuEqStats
end

function MyAddon:fuEqStatsOff(info, value)
    _G["AddonUiDB"].profile.fuEqStats = value
end